package com.air.ota.vo;

import com.air.ota.util.HexStringUtil;

/**
 * @author Marco
 * @param pckLength 包长度  类型hex 长度2
 * @param syncCode  同步信息  类型hex 长度2
 * @param compressMethod 压缩/算法  类型hex 长度1
 * @param messageType 消息类型  类型bcd 长度2 0x9000
 * @param messageVer 消息版本  类型hex 长度1 0x01
 * @param requireId 请求方编号  类型bcd 长度6 0x000000000000
 * @param destId 目标方编号  类型bcd 长度6 0x000000000000
 * @param responseCode 交易应答码  类型hex 长度1 0x00
 * @param serversType 服务类型  类型asc 长度4 
 * @param data 交易数据  类型asc 长度不定
 * @param mac 对包体计算的MAC  类型hex 长度4 0x00000000
 */

public abstract class SZTBaseRequestVO {
	
	protected byte[] pckLength;
	protected byte[] syncCode; 
	protected byte   compressMethod;
	
	protected byte[] messageType;
	protected byte   messageVer;
	protected byte[] requireId;
	protected byte[] destId;
	protected byte   responseCode;
	
	protected String serversType;
	protected String data;
	
	protected byte[] mac;
	
	
	
	
	public SZTBaseRequestVO(){
		syncCode = HexStringUtil.hexStringToBytes("0000");
		compressMethod = 0x00;
		messageType = HexStringUtil.hexStringToBytes("9000");
		messageVer = 0x01;
		requireId = HexStringUtil.hexStringToBytes("000000000000");
		destId =  HexStringUtil.hexStringToBytes("000000000000");
		responseCode = 0x00;
		
		
		
		mac = HexStringUtil.hexStringToBytes("00000000");
	}
	
	
	public String getMsgPackage(){
		StringBuffer hexStringBuf = new StringBuffer();
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.syncCode));
		hexStringBuf.append(HexStringUtil.byteToHexString(this.compressMethod));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.messageType));
		hexStringBuf.append(HexStringUtil.byteToHexString(this.messageVer));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.requireId));
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.destId));
		hexStringBuf.append(HexStringUtil.byteToHexString(this.responseCode));
		
		hexStringBuf.append(HexStringUtil.asc2Hex(this.serversType));
		hexStringBuf.append(HexStringUtil.asc2Hex(this.data));
		//System.out.println("hahah===="+HexStringUtil.asc2Hex(this.data).length());
		
		hexStringBuf.append(HexStringUtil.bytesToHexString(this.mac));
		
		int pkgLength = HexStringUtil.hexStringToBytes(hexStringBuf.toString()).length;
		String lengthHexString = getPkgLenHexString(pkgLength);
		
		
		
		return lengthHexString+hexStringBuf.toString();
	}
	
	public String getPkgLenHexString(int length){
		int fillCount = 0; 
		String hexString = Integer.toHexString(length);
		fillCount = 4-hexString.length();
		for(int i=0;i<fillCount;i++){
			hexString = "0"+hexString;
		}
		String lengthHexString = hexString.substring(2, 4)+hexString.substring(0,2);
		
		
		return lengthHexString;
	}
	
	
	public byte[] getPckLength() {
		return pckLength;
	}

	public void setPckLength(byte[] pckLength) {
		this.pckLength = pckLength;
	}

	public byte[] getSyncCode() {
		return syncCode;
	}

	public void setSyncCode(byte[] syncCode) {
		this.syncCode = syncCode;
	}

	public byte getCompressMethod() {
		return compressMethod;
	}

	public void setCompressMethod(byte compressMethod) {
		this.compressMethod = compressMethod;
	}

	public byte[] getMessageType() {
		return messageType;
	}

	public void setMessageType(byte[] messageType) {
		this.messageType = messageType;
	}

	public byte getMessageVer() {
		return messageVer;
	}

	public void setMessageVer(byte messageVer) {
		this.messageVer = messageVer;
	}

	public byte[] getRequireId() {
		return requireId;
	}

	public void setRequireId(byte[] requireId) {
		this.requireId = requireId;
	}

	public byte[] getDestId() {
		return destId;
	}

	public void setDestId(byte[] destId) {
		this.destId = destId;
	}

	public byte getResponseCode() {
		return responseCode;
	}

	public void setResponseCode(byte responseCode) {
		this.responseCode = responseCode;
	}

	public String getServersType() {
		return serversType;
	}

	public void setServersType(String serversType) {
		this.serversType = serversType;
	}

	public String getData() {
		return data;
	}

	public void setData(String data) {
		this.data = data;
	}

	public byte[] getMac() {
		return mac;
	}

	public void setMac(byte[] mac) {
		this.mac = mac;
	}
	
	
	
}
